package cn.afactory.tygz.nav;

import android.app.Activity;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.view.View;

import com.baidu.navisdk.adapter.BNRouteGuideManager;
import com.baidu.navisdk.adapter.BNRouteGuideManager.OnNavigationListener;
import com.baidu.navisdk.adapter.BNRoutePlanNode;

/**
 * 诱导界面
 * @author sunhao04
 *
 */
public class NavGuideActivity extends Activity {
	public static final String ROUTE_PLAN_NODE = "routePlanNode";
	private BNRoutePlanNode mBNRoutePlanNode = null;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {}
		View view = BNRouteGuideManager.getInstance().onCreate(this, new OnNavigationListener() {
			
			@Override
			public void onNaviGuideEnd() {
				finish();
			}
			
			@Override
			public void notifyOtherAction(int actionType, int arg1, int arg2, Object obj) {
				
			}
		});
		
		if ( view != null ) {
			setContentView(view);
		}
		
		Intent intent = getIntent();
		if (intent != null) {
			Bundle bundle = intent.getExtras();
			if (bundle != null) {
			    mBNRoutePlanNode = (BNRoutePlanNode) bundle.getSerializable(NavGuideActivity.ROUTE_PLAN_NODE);
			}
		}
	}
	
	@Override
	protected void onResume() {
		BNRouteGuideManager.getInstance().onResume();
		super.onResume();
	}
	
	protected void onPause() {
		super.onPause();
		BNRouteGuideManager.getInstance().onPause();
	};
	
	@Override
	protected void onDestroy() {
		BNRouteGuideManager.getInstance().forceQuitNaviWithoutDialog();
		BNRouteGuideManager.getInstance().onDestroy();
		super.onDestroy();
	}
	
	@Override
	protected void onStop() {
		BNRouteGuideManager.getInstance().onStop();
	    super.onStop();
	}
	
	@Override
	public void onBackPressed() {
		BNRouteGuideManager.getInstance().onBackPressed(false);
	}
	
	public void onConfigurationChanged(android.content.res.Configuration newConfig) {
		BNRouteGuideManager.getInstance().onConfigurationChanged(newConfig);
		super.onConfigurationChanged(newConfig);
	};
}
